/*
 * 	Name		: CMX998.h
 *	Author	 	: Tigran Papazyan
 *  Created on	: Dec 17, 2010
 *  Copyright   : Copyright Antel Systems
 *  Description : CMX998 Driver
 */

#ifndef CMX998_H_
#define CMX998_H_

#define CMX_SET_WITH_NO_ERR		1
#define CMX_SET_WITH_ERR		0

unsigned char CMX998_General_Reset_Command ;						//0x01

struct CMX998_Write_General_Control_Register_Struct
{
	unsigned char	address;										//0x02
	union
	{
		struct
		{
			unsigned char	Fwd_Pwr :1 ;
			unsigned char	FB_Pwr :1 ;
			unsigned char	Vbias :1 ;
			unsigned char	Filt_Pwr :1 ;
			unsigned char	Input_Amp_Pwr :1 ;
			unsigned char	Error_Amp_Pwr :1 ;
			unsigned char	Open_loop :1 ;
			unsigned char	Error_Amp_Gain_Red :1 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
} CMX998_Write_General_Control_Register;
unsigned char CMX998_Read_General_Control_Register;					//0xF2


struct CMX998_Write_Phase_Control_Register_Struct
{
	unsigned char	address;										//0x03
	union
	{
		struct
		{
			unsigned char Phase_Shift_Setting :5 ;
			unsigned char Reserved :3 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
}CMX998_Write_Phase_Control_Register;
unsigned char CMX998_Read_Phase_Control_Register;					//0xF3


struct CMX998_Write_Gain_Control_Register_struct
{
	unsigned char	address;										//0x04
	union
	{
		struct
		{
			unsigned short Forward_Path_Attenuation :5 ;
			unsigned short Set_to_zero :5 ;
			unsigned short Feedback_Path_Attenuation :5 ;
			unsigned short Set_zero:1 ;
		}Bit_val;
		unsigned short WORD_val ;
	};
}CMX998_Write_Gain_Control_Register ;
unsigned char CMX998_Read_Gain_Control_Register ;					//0xF4


struct CMX998_Write_Forward_Path_Gain_Control_Register_struct
{
	unsigned char	address;										//0x05
	union
	{
		struct
		{
			unsigned char Forward_Path_Gain_Control :5 ;
			unsigned char set_to_zero :3 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
}CMX998_Write_Forward_Path_Gain_Control_Register;
unsigned char CMX998_Read_Forward_Path_Gain_Control_Register ;		//0xF5


struct CMX998_Write_Feedback_Path_Gain_Control_Register_struct
{
	unsigned char	address;										//0x06
	union
	{
		struct
		{
			unsigned char set_to_zero :1 ;
			unsigned char Forward_Path_Gain_Control :7 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
}CMX998_Write_Feedback_Path_Gain_Control_Register;
unsigned char CMX998_Read_Feedback_Path_Gain_Control_Register ;		//0xF6


struct CMX998_Write_Aux_Control_Register_struct
{
	unsigned char	address;										//0x07
	union
	{
		struct
		{
			unsigned char DC_On :1 ;
			unsigned char Instab_Det_Enable :1 ;
			unsigned char RFDet_On :1 ;
			unsigned char DCMEAS :1 ;
			unsigned char IS :2 ;
			unsigned char DC :2 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
}CMX998_Write_Aux_Control_Register ;
unsigned char CMX998_Read_Aux_Control_Register ;					//0xF7


struct CMX998_Write_Frequency_Control_Register_struct
{
	unsigned char	address;										//0x08
	union
	{
		struct
		{
			unsigned char set_to_zero :3 ;
			unsigned char DIV :1 ;
			unsigned char set_zero :2 ;
			unsigned char F :2 ;
		}Bit_val;
		unsigned char BYTE_val ;
	};
}CMX998_Write_Frequency_Control_Register ;
unsigned char CMX998_Read_Frequency_Control_Register ;				//0xF8

int CMX998_Initialize(float power);
int CMX998_Write(unsigned char CMX998_reg_address ,unsigned char data);
int CMX998_Read(unsigned char CMX998_reg_address ,unsigned char* data);
int CMX998_Power_Down(void);

unsigned short CMX998_RF_Power_Detector_Read(unsigned int average);

void CMX998_Output_Power_Calibration(void);
unsigned short CMX998_Phase_Shift_Search(unsigned short Center_ponint);
unsigned short CMX998_Phase_Shift_Search_procedure(unsigned short Center_ponint);
unsigned short CMX998_Instability_Detector_Read(unsigned int average);

unsigned short CMX998_Find_Feedback_Att_Value(unsigned short PD_Ref);

unsigned short CMX998_NC_Antenna_protection(void);

int CMX998_Set_Output_Power_dBm(double power_dbm , char no_error);
int CMX998_Set_Output_Power_lvl(char power_lvl);


#endif
